<template>
	<div class="mainDiv">
        <div class="rowHead flex_center">
            <el-button style="margin-right: 5px;" icon="plus" type="success" @click="add" v-qx="permission.add">新增分店</el-button>
            <el-select style="margin-right: 5px;" v-model="page.zt" class="ml" @change="updateList" v-qx="permission.status">
                <el-option v-for="s in status" :label="s.txt" :value="s.val" :key="s.val">
                </el-option>
            </el-select>
            <el-input v-model="page.search" placeholder="搜索分店名称" @keyup.enter.native="updateList" style="width:200px">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="updateList"></i>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true">
            <el-table-column type="index" label="ID"></el-table-column>
            <el-table-column prop="name" label="分店名称"></el-table-column>
            <el-table-column prop="orcode" label="机构码"></el-table-column>
            <el-table-column prop="phone" label="联系方式"></el-table-column>
            <el-table-column prop="province" label="省份"></el-table-column>
            <el-table-column prop="city" label="城市"></el-table-column>
            <el-table-column prop="area" label="区域"></el-table-column>
            <el-table-column prop="address" label="街道地址" show-overflow-tooltip></el-table-column>
            <el-table-column prop="isdisable" label="分店状态">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.isdisable">停用</el-tag>
                    <el-tag type="primary" v-else>正常</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="设置" width="240">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisable">
                        <el-button type="warning" icon="edit" size="small" @click="editShop(scope.row)" v-qx="permission.edit">编辑</el-button>
                        <el-tooltip content="权限配置" placement="left" :open-delay="800" v-qx="permission.set">
                            <el-button icon="h-quanxian" type="primary" size="small" @click="quanxian(scope.row.id)">权限配置</el-button>
                        </el-tooltip>
                        <el-tooltip content="关闭分店" placement="top" :open-delay="800" v-qx="permission.unstop">
                            <el-button icon="h-jinyong" type="danger" size="small" @click="zhuangtai(scope.row.id,1)">关闭分店</el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-tooltip content="重新打开分店" placement="left" :open-delay="800" v-else v-qx="permission.unstop">
                        <el-button icon="h-qiyong2" type="success" size="small" @click="zhuangtai(scope.row.id,0)">重新打开分店</el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div class="block center bg-light">
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
export default {
  name: 'shopList',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: '',
        zt: 0
      },
      status: [{
        txt: '正常',
        val: 0
      },
      {
        txt: '停用',
        val: 1
      }],
      permission: {
        add: 'shop_add',
        edit: 'shop_edit',
        status: 'shop_status',
        set: 'shop_set',
        unstop: 'shop_unstop'
      }
    }
  },
  mounted () {
    this.updateList()
  },
  methods: {
    async add () {
      let res = await C.openBrowserWindow('/addShop', {}, {
        transparent: true,
        frame: false,
        width: 500,
        height: 340,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.updateList()
      }
    },
    async editShop (row) {
      let res = await C.openBrowserWindow('/addShop', { row: row }, {
        transparent: true,
        frame: false,
        width: 600,
        height: 440,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.updateList()
      }
    },
    async quanxian (id) {
      await C.openBrowserWindow('/shopadminEdit', { shopid: id }, {
        transparent: true,
        frame: false,
        width: 1200,
        height: 800,
        useSpa: false,
        spaModel: 'organization'
      })
    },
    async zhuangtai (id, st) {
      let that = this
      if (st) {
        C.confirm('关闭当前分店, 是否继续?', async () => {
          let res = await C.ajax('/organization/shop/unstop', { id: id, st: st }, 'post')
          if (res) {
            that.updateList()
            C.success(res.data)
          }
        })
      } else {
        let res = await C.ajax('/organization/shop/unstop', { id: id, st: st }, 'post')
        if (res) {
          C.success(res.data)
          that.updateList()
        }
      }
    },
    sizeChange (val) {
      this.page.limits = val
      this.updateList()
    },
    currentChange (val) {
      this.page.pages = val
      this.updateList()
    },
    async updateList () {
      let data = await C.ajax('/organization/shop/shoplist', this.page, 'post')
      if (data) {
        this.total = data.count
        this.list = data.data
      }
    }
  }
}
</script>


